import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import BaiduMap from 'vue-baidu-map'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/fonts/iconfont.css'
import 'swiper/swiper-bundle.css'
import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

Vue.use(BaiduMap, {
  ak: 'N5rTOkGVQBbjw8MmbEkGfXbY0Vfi1jo1' // 请替换为你的 API 密钥  
})
Vue.use(ElementUI, { size: 'medium' })
Vue.config.productionTip = false
import moment from "moment"; // 导入moment模块
moment.locale("zh-cn"); // 设置语言 或 moment.lang('zh-cn');
Vue.prototype.$moment = moment; // 赋值使用

import $baseUrl from '@/utils/baseURL'
import $public from '@/utils/public'
import {
  dateToFormat,
  dateToFormattwo,
  dateToFormatname,
  dateToFormatthree, toLocal
} from "@/utils/validate";
//在main.js中添加配置

//引入组件
import { Message } from 'element-ui'

//注意：这里使用的$message,所以在使用时候也是this.$message
Vue.prototype.$message = function (msg) {
  Message.closeAll();
  return Message({
    message: msg,
    duration: 800
  })
}
//分别对success、warning和error等样式进行设置
Vue.prototype.$message.success = function (msg) {
  Message.closeAll();
  return Message.success({
    message: msg,
    duration: 800,
    showClose: true
  })
}
Vue.prototype.$message.warning = function (msg) {
  Message.closeAll();
  return Message.warning({
    message: msg,
    duration: 20000,
    showClose: true
  })
}
Vue.prototype.$message.error = function (msg) {
  Message.closeAll();
  return Message.error({
    message: msg,
    duration: 20000,
    showClose: true
  })
}
Vue.prototype.dateToFormat = dateToFormat;
Vue.prototype.dateToFormattwo = dateToFormattwo;
Vue.prototype.dateToFormatname = dateToFormatname;
Vue.prototype.dateToFormatthree = dateToFormatthree;
Vue.prototype.toLocal = toLocal;
Vue.prototype.$cloudBaseurl = $baseUrl.cloudBaseurl;
Vue.prototype.$agricultureServiceUrl = $baseUrl.agricultureServiceUrl;
Vue.prototype.$webSocketCaramsUrl = $baseUrl.webSocketCaramsUrl;
Vue.prototype.$webServiceUrl = $baseUrl.webServiceUrl;
Vue.prototype.$public = $public;
Vue.prototype.$baseurl = $baseUrl;
Vue.directive('tableMove', {
  bind: function (el, binding, vnode) {
    var odiv = el; // 获取当前表格元素  
    var mouseDownAndUpTimer = null;
    var mouseOffset = 0;
    var mouseFlag = false;

    // 添加可拖动样式  
    odiv.querySelector('.el-table__body-wrapper').style.cursor = 'grab';

    odiv.onmousedown = (e) => {
      if (e.which !== 1) return;
      mouseOffset = e.clientX;
      mouseDownAndUpTimer = setTimeout(function () {
        mouseFlag = true;
      }, 1);
    };

    odiv.onmouseup = (e) => {
      if (mouseFlag) {
        mouseFlag = false;
      } else {
        clearTimeout(mouseDownAndUpTimer); // 清除延迟时间  
      }
    };

    odiv.onmouseleave = (e) => {
      mouseFlag = false;
    };

    odiv.onmousemove = (e) => {
      if (e.which !== 1 || !mouseFlag) return;
      const divData = odiv.querySelector('.el-table__body-wrapper');
      if (divData) {
        // 设置水平方向的元素的位置  
        divData.scrollLeft -= (-mouseOffset + (mouseOffset = e.clientX));
      }
    };

    // 阻止默认拖动行为  
    odiv.ondragstart = (e) => {
      e.preventDefault();
    };
  }
});
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
